<?php
/**
 * Author: yixuan
 * Desc:
 * Time: 2016/6/8 18:00
 */

if (!function_exists('xhtmlspecialchars')) {
    function xhtmlspecialchars($var)
    {
        if (is_array($var)) {
            foreach ($var as $key => $value) {
                $var[htmlspecialchars($key)] = xhtmlspecialchars($value);
            }
        } else {
            $var = str_replace('&amp;', '&', htmlspecialchars($var, ENT_QUOTES));
        }
        return $var;
    }
}
if (!function_exists('xserializer')) {
    function xserializer($value)
    {
        return serialize($value);
    }
}

if (!function_exists('xunserializer')) {
    function xunserializer($value)
    {
        if (empty($value)) {
            return array();
        }
        if (!is_serialized($value)) {
            return $value;
        }
        if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
            $result = unserialize($value, array('allowed_classes' => false));
        } else {
            if (preg_match('/[oc]:[^:]*\d+:/i', $seried)) {
                return array();
            }
            $result = unserialize($value);
        }
        if ($result === false) {
            $temp = preg_replace_callback('!s:(\d+):"(.*?)";!s', function ($matchs) {
                return 's:' . strlen($matchs[2]) . ':"' . $matchs[2] . '";';
            }, $value);
            return unserialize($temp);
        } else {
            return $result;
        }
    }
}
if (!function_exists('is_error')) {
    function is_error($data)
    {
        if (empty($data) || !is_array($data) || !array_key_exists('errno', $data) || (array_key_exists('errno', $data) && $data['errno'] == 0)) {
            return false;
        } else {
            return true;
        }
    }
}

if (!function_exists('array2xml')) {
    function array2xml($arr, $level = 1)
    {
        $s = $level == 1 ? "<xml>" : '';
        foreach ($arr as $tagname => $value) {
            if (is_numeric($tagname)) {
                $tagname = $value['TagName'];
                unset($value['TagName']);
            }
            if (!is_array($value)) {
                $s .= "<{$tagname}>" . (!is_numeric($value) ? '<![CDATA[' : '') . $value . (!is_numeric($value) ? ']]>' : '') . "</{$tagname}>";
            } else {
                $s .= "<{$tagname}>" . array2xml($value, $level + 1) . "</{$tagname}>";
            }
        }
        $s = preg_replace("/([\x01-\x08\x0b-\x0c\x0e-\x1f])+/", ' ', $s);
        return $level == 1 ? $s . "</xml>" : $s;
    }
}

if (!function_exists('is_serialized')) {
    function is_serialized($data, $strict = true)
    {
        if (!is_string($data)) {
            return false;
        }
        $data = trim($data);
        if ('N;' == $data) {
            return true;
        }
        if (strlen($data) < 4) {
            return false;
        }
        if (':' !== $data[1]) {
            return false;
        }
        if ($strict) {
            $lastc = substr($data, -1);
            if (';' !== $lastc && '}' !== $lastc) {
                return false;
            }
        } else {
            $semicolon = strpos($data, ';');
            $brace = strpos($data, '}');
            if (false === $semicolon && false === $brace)
                return false;
            if (false !== $semicolon && $semicolon < 3)
                return false;
            if (false !== $brace && $brace < 4)
                return false;
        }
        $token = $data[0];
        switch ($token) {
            case 's' :
                if ($strict) {
                    if ('"' !== substr($data, -2, 1)) {
                        return false;
                    }
                } elseif (false === strpos($data, '"')) {
                    return false;
                }
            case 'a' :
                return (bool)preg_match("/^{$token}:[0-9]+:/s", $data);
            case 'O' :
                return false;
            case 'b' :
            case 'i' :
            case 'd' :
                $end = $strict ? '$' : '';
                return (bool)preg_match("/^{$token}:[0-9.E-]+;$end/", $data);
        }
        return false;
    }
}

if (!function_exists('tomedia')) {
    function tomedia($value)
    {
        return $value;
    }
}
if (!function_exists('file_delete')) {
    function file_delete($file)
    {
        global $_W;
        if (empty($file)) {
            return false;
        }
        if (file_exists($file)) {
            @unlink($file);
        }
        if (file_exists(ATTACHMENT_ROOT . '/' . $file)) {
            @unlink(ATTACHMENT_ROOT . '/' . $file);
        }

        return true;
    }
}
if (!function_exists('view_form_field_date')) {
    /**
     * Desc: 单选时间
     * User: yixuan
     * Time: 2016/7/13 11:16
     * @param $name  表单input名称
     * @param $value 表单input值
     * @param $withtime 是否显示时间
     */
    function view_form_field_date($name, $value = '', $withtime = false)
    {
        if ($value < '2019-01-00 00:00:00' || $value == '') {
            $value2 = date("Y-m-d 00:00:00", strtotime('-1 month'));
        } else {
            $value2 = $value;
        }
        if ($withtime) {
            $timedata = " type: 'datetime',";
        } else {
            $timedata = "";
        }
        $name_id = $name . "_fielddate";
        return "
            <div class=''>
                <input type='text' class='form-control' id='" . $name_id . "'  value='" . $value2 . "'>
                <input type='hidden' id='" . $name . "' name='" . $name . "' value='" . $value . "'>
            </div>
            <script >
                layui.use('laydate', function(){
                    var laydate = layui.laydate;
                     //日期时间选择器
                      laydate.render({
                        elem: '#" . $name_id . "',
                        " . $timedata . "
                        btns: ['now','confirm'],
                        done: function(value){ // 配置完成后回调，手动给input赋值
                              $('#" . $name . "').val(value);
                          }
                      });
               });
            </script>
        ";
    }
}
if (!function_exists('view_form_field_daterange')) {
    /**
     * Desc: 时间范围选择
     * User: yixuan
     * Time: 2016/7/13 10:32
     * @param $name 表单input名称
     * @param $value 表单input值
     * @param $time 是否显示时间
     */
    function view_form_field_daterange($name, $value, $show_time = false)
    {
        global $_P;
        $start = $_P[$name]['start'] ? $value['start'] : $value['start'];
        $end = $_P[$name]['end'] ? $_P[$name]['end'] : $value['end'];
        if ($show_time === true) {
            $start = date("Y-m-d H:i:s", strtotime($start));
            $end = date("Y-m-d H:i:s", strtotime($end));
            $timedate = " type: 'datetime',";
        } else {
            $start = date("Y-m-d", strtotime($start));
            $end = date("Y-m-d", strtotime($end));
            $timedate = " ";
        }

        $input = $start . " 至 " . $end;
        $id_start = $name . '_start';
        $id_end = $name . '_end';
        return "
        <div class='layui-input-inline'>
            <input type='text' class='layui-input' id='" . $name . "_daterange' style='width: 330px;' value='" . $input . "'>
            <input name='" . $name . "[start]' type='hidden' id='" . $id_start . "' value='" . $value['start'] . "' />
            <input name='" . $name . "[end]' type='hidden' id='" . $id_end . "' value='" . $value['end'] . "' />
        </div>
        <script>
            layui.use('laydate', function(){
                var laydate = layui.laydate;
                // 配置日期范围选择器
                laydate.render({
                    elem: '#" . $name . "_daterange',
                   " . $timedate . "
                    range: '至', // 开启范围选择
                    btns: ['confirm'],
                    rangeLinked: true
                    ,done: function(value, date, endDate){ // 配置完成后回调，手动给input赋值
                        var startDate = new Date(date.year, date.month - 1, date.date, date.hours, date.minutes, date.seconds);
                        var endDate = new Date(endDate.year, endDate.month - 1, endDate.date, endDate.hours, endDate.minutes, endDate.seconds);
                        var startDateFormatted = formatDate(startDate);
                        var endDateFormatted = formatDate(endDate);
                        $('#" . $id_start . "').val(startDateFormatted);
                        $('#" . $id_end . "').val(endDateFormatted);
                    }
                });
            });
            function formatDate(date) {
                var year = date.getFullYear();
                var month = (date.getMonth() + 1).toString().padStart(2, '0');
                var day = date.getDate().toString().padStart(2, '0');
                var hours = date.getHours().toString().padStart(2, '0');
                var minutes = date.getMinutes().toString().padStart(2, '0');
                var seconds = date.getSeconds().toString().padStart(2, '0');
                return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
            }
        </script>
        ";
    }
}
if (!function_exists('view_form_field_color')) {
    /**
     * Desc:拾色器
     * User: yixuan
     * Time: 2016/7/13 13:55
     * @param $name
     * @param $value
     */
    function view_form_field_color($name, $value = '')
    {
        $name_color_from = $name . "color_from";
        return "
            <style>.layui-colorpicker{width: 38px;height: 38px;}.layui-colorpicker-main{width: 300px;}</style>
            <div style='margin-left: 30px;'>
                <div class='layui-form-item'>
                    <div class='layui-input-inline' style='width: 120px;'>
                        <input type='text' id='" . $name . "' name='" . $name . "' value='" . $value . "' placeholder='请选择颜色' class='layui-input' />
                    </div>
                    <div class='layui-inline' style='left: -11px;'>
                        <div id='" . $name_color_from . "'></div>
                    </div>
                </div>
            </div>
            <script>
                layui.use('colorpicker', function(){
                    var colorpicker = layui.colorpicker;
                    //表单赋值
                    colorpicker.render({
                        elem: '#" . $name_color_from . "'
                        ,color: '" . $value . "'
                        ,predefine: true
                        ,colors : [
    // 白色系
    '#FFFFFF',  // 白色
    '#FFFFCC',
    '#FFFF99',
    '#FFFF66',
    '#FFFF33',
    '#FFFF00',  // 黄色

    // 黄色系（浅至深）
    '#FFD700',  // 金色（gold）
    '#FFCC00',
    '#FFC000',
    '#FFA500',  // 橙色（orange）
    '#FF8C00',  // 橙色

    // 橙红色系（浅至深）
    '#FF9999',
    '#FF6666',
    '#FF3333',
    '#FF0000',  // 红色

    // 红紫色系（浅至深）
    '#FF69B4',  // 粉红玫瑰红（hot pink）
    '#FF00FF',  // 粉红色（magenta）
    '#CC00FF',
    '#9900FF',
    '#6600FF',
    '#3300FF',
    '#0000FF',  // 蓝色

    // 蓝色系（浅至深）
    '#33B5E5',  // 清澈蓝色（light blue）
    '#0099CC',
    '#0066CC',
    '#0033CC',
    '#000099',
    '#000066',
    '#000033',
    '#000000',  // 黑色

    // 绿色系（浅至深）
    '#CCFFCC',
    '#99FF99',
    '#66FF66',
    '#33FF33',
    '#00FF00',  // 鲜绿色（lime）
    '#00CC00',
    '#009900',
    '#006600',
    '#003300',

    // 青色（cyan）系（浅至深）
    '#CCFFFF',
    '#99FFFF',
    '#66FFFF',
    '#33FFFF',
    '#00FFFF',  // 青色（cyan）
]

                        ,done: function(color){
                        $('#" . $name . "').val(color);
                        }
                    });
                });
            </script>
        ";
    }
}
// 单图选择与批量上传功能
if (!function_exists('view_form_field_image_sold')) {
    function view_form_field_image_sold($name, $value = '', $default = '', $options = array(), $sold_tips = '')
    {
        $btnDesc = '选择图片(单选)';

        if ($value) {
            $elementString = <<<EOF
        <div class="input-group">
            <input type="text" name="$name" value="$value" class="form-control" aria-label="${btnDesc}">
            <div class="input-group-btn">
                <!-- 触发 Modal 的按钮 -->
                <button type="button" class="btn btn-default" data-operate-type="图片" data-is-multiple="false"  data-toggle="modal" data-target="#uploadModal">
                     选择图片(单选)
                </button>

            </div>
        </div>
        <div class="select-wrapper">
            <div class="selected-batch">
                <i class="fa fa-times" data-test="hello world" aria-hidden="true" onclick="deleteSingleImage(this)"></i>
                <img class="img-thumbnail" style="max-width: 150px; max-height: 150px;" src="${value}" alt="" />
            </div>
        </div>
EOF;
        } else {
            $elementString = <<<EOF
        <div class="input-group">
            <input type="text" name="$name" value="$value" class="form-control" aria-label="${btnDesc}">
            <div class="input-group-btn">
                <!-- 触发 Modal 的按钮 -->
                <button type="button" class="btn btn-default" data-operate-type="图片" data-is-multiple="false"  data-toggle="modal" data-target="#uploadModal">
                     选择图片(单选)
                </button>

            </div>
        </div>
        <div class="select-wrapper">
            <div class="selected-batch">
                <i class="fa fa-times" data-test="hello world" aria-hidden="true" onclick="deleteSingleImage(this)"></i>
                <img class="img-thumbnail" style="max-width: 150px; max-height: 150px;" src="/resource/images/nopic.jpg" alt="" />
            </div>
        </div>
EOF;
        }


        $scriptString = <<<EOF
            <script type="text/javascript">

                // 删除当前选择的图片
                function deleteSingleImage(el){
                    var defaultCover = "/resource/images/nopic.jpg"
                    var currentCover = $(el).next().attr("src")
                    $(el).parent().parent().prev().find("input").val("");
                    if(defaultCover == currentCover) {
                        console.log("默认封面，无需触发HTTP对图片的请求")
                        return
                    } else {
                        $(el).next().attr("src", defaultCover);
                        console.log("重置封面，触发默认封面的新请求")
                    }
                }
        </script>
EOF;
        return $elementString . $scriptString;
    }
}
// 单图选择与批量上传功能
if (!function_exists('view_form_field_image')) {
    function view_form_field_image($name, $value = '')
    {
        $btnDesc = '选择图片(单选)';

        if ($value) {
            $elementString = <<<EOF
        <div class="input-group">
            <input type="text" name="$name" value="$value" class="form-control" aria-label="${btnDesc}">
            <div class="input-group-btn">
                <!-- 触发 Modal 的按钮 -->
                <button type="button" class="btn btn-default" data-operate-type="图片" data-is-multiple="false"  data-toggle="modal" data-target="#uploadModal">
                     选择图片(单选)
                </button>

            </div>
        </div>
        <div class="select-wrapper">
            <div class="selected-batch">
                <i class="fa fa-times" data-test="hello world" aria-hidden="true" onclick="deleteSingleImage(this)"></i>
                <img class="img-thumbnail" style="max-width: 150px; max-height: 150px;" src="${value}" alt="" />
            </div>
        </div>
EOF;
        } else {
            $elementString = <<<EOF
        <div class="input-group">
            <input type="text" name="$name" value="$value" class="form-control" aria-label="${btnDesc}">
            <div class="input-group-btn">
                <!-- 触发 Modal 的按钮 -->
                <button type="button" class="btn btn-default" data-operate-type="图片" data-is-multiple="false"  data-toggle="modal" data-target="#uploadModal">
                     选择图片(单选)
                </button>

            </div>
        </div>
        <div class="select-wrapper">
            <div class="selected-batch">
                <i class="fa fa-times" data-test="hello world" aria-hidden="true" onclick="deleteSingleImage(this)"></i>
                <img class="img-thumbnail" style="max-width: 150px; max-height: 150px;" src="/resource/images/nopic.jpg" alt="" />
            </div>
        </div>
EOF;
        }


        $scriptString = <<<EOF
            <script type="text/javascript">

                // 删除当前选择的图片
                function deleteSingleImage(el){
                    var defaultCover = "/resource/images/nopic.jpg"
                    var currentCover = $(el).next().attr("src")
                    $(el).parent().parent().prev().find("input").val("");
                    if(defaultCover == currentCover) {
                        console.log("默认封面，无需触发HTTP对图片的请求")
                        return
                    } else {
                        $(el).next().attr("src", defaultCover);
                        console.log("重置封面，触发默认封面的新请求")
                    }
                }
        </script>
EOF;
        return $elementString . $scriptString;
    }
}

// 多图选择与批量上传功能
if (!function_exists('view_form_field_multi_image')) {
    function view_form_field_multi_image($name, $value)
    {
        $btnDesc = '选择图片(多选)';

        if (is_array($value) && count($value) > 0) {

            $imgListString = '';

            foreach ($value as $imgSrcLink) {
                $imgListString .= <<<EOF
<div class="selected-batch">
<input type="hidden"  name="${name}[]" readonly value="${imgSrcLink}" class="form-control" aria-label="$btnDesc">
<i class="fa fa-times" aria-hidden="true" onclick="deleteImage(this)"></i>
<img class="img-thumbnail" style="max-width: 150px; max-height: 150px;" src="${imgSrcLink}" alt="" />
</div>
EOF;
            }

            $elementString = <<<EOF
        <div class="input-group">
        <input type="text" readonly data-name="${name}" value="批量上传图片" class="form-control" aria-label="${btnDesc}">
        <div class="input-group-btn">
            <!-- 触发 Modal 的按钮 -->
            <button type="button" class="btn btn-default" data-operate-type="图片" data-is-multiple="true"  data-toggle="modal" data-target="#uploadModal">
                 选择图片(多选)
            </button>

        </div>
        </div>
        <div class="select-wrapper">${imgListString}</div>
EOF;
        } else {
            $elementString = <<<EOF
        <div class="input-group">
        <input type="text" readonly data-name="${name}" value="批量上传图片" class="form-control" aria-label="${btnDesc}">
        <div class="input-group-btn">
            <!-- 触发 Modal 的按钮 -->
            <button type="button" class="btn btn-default" data-operate-type="图片" data-is-multiple="true"  data-toggle="modal" data-target="#uploadModal">
                 选择图片(多选)
            </button>

        </div>
        </div>
        <div class="select-wrapper"></div>
EOF;
        }


        $scriptString = <<<EOF
            <script type="text/javascript">
                // 删除当前选择的图片
                function deleteImage(el){
                    $(el).parent().remove();
                    return ;
                }
        </script>
EOF;
        return $elementString . $scriptString;
    }
}

// 单音频选择与批量上传功能
if (!function_exists('view_form_field_audio')) {
    function view_form_field_audio($name, $value)
    {
        $btnDesc = '选择音频(单选)';
        $elementString = <<<EOF
        <div class="input-group">
            <input type="text" name="$name" value="$value" class="form-control audio-player-media" aria-label="${btnDesc}">
            <div class="input-group-btn">
                <button class="btn btn-default audio-player-play" type="button"><i class="fa fa-play"></i></button>
                <button type="button" class="btn btn-default" data-operate-type="音频" data-is-multiple="false"  data-toggle="modal" data-target="#uploadModal">
                     选择媒体文件(音频单选)
                </button>
            </div>
            <div class="input-group audio-player"></div>
        </div>
        <div class="select-wrapper">
<!--            <div class="selected-batch">-->
<!--                <i class="fa fa-times" aria-hidden="true" onclick="deleteImage(this)"></i>-->
<!--                <img class="img-thumbnail" style="max-width: 150px; max-height: 150px;" src="/resource/images/nopic.jpg" alt="" />-->
<!--            </div>-->
        </div>
EOF;
        $scriptString = <<<EOF
            <script type="text/javascript">
                // 删除当前选择的图片
                function deleteImage(el){
                    $(el).parent().remove();
                    return ;
                }

            function setAudioPlayer(){
                $(".audio-player").each(function(){
                    $(this).prev().find("button").eq(0).click(function(){
                        var src = $(this).parent().parent().find('input').val();
                        if($(this).find("i").hasClass("fa-stop")) {
                            $(this).parent().next().jPlayer("stop");
                        } else {
                            if(src) {
                                $(this).parent().next().jPlayer("setMedia", {mp3: src }).jPlayer("play");
                            }
                        }
                    });
                });

                $(".audio-player").jPlayer({
                    playing: function() {
                        $(this).prev().find("i").removeClass("fa-play").addClass("fa-stop");
                    },
                    pause: function (event) {
                        $(this).prev().find("i").removeClass("fa-stop").addClass("fa-play");
                    },
                    swfPath: "resource/components/jplayer",
                    supplied: "mp3"
                });

            }
	setAudioPlayer();


        </script>
EOF;
        return $elementString . $scriptString;
    }
}

// 单视频选择与批量上传功能
if (!function_exists('view_form_field_video')) {
    function view_form_field_video($name, $value)
    {
        $btnDesc = '选择视频(单选)';
        $elementString = <<<EOF
        <div class="input-group">
        <input type="text" name="$name" value="$value" class="form-control" aria-label="${btnDesc}">
        <div class="input-group-btn">
            <!-- 触发 Modal 的按钮 -->
            <button type="button" class="btn btn-default" data-operate-type="视频" data-is-multiple="false"  data-toggle="modal" data-target="#uploadModal">
                 选择媒体文件(视频单选)
            </button>
        </div>
        </div>
        <div class="select-wrapper">
<!--            <div class="selected-batch">-->
<!--                <i class="fa fa-times" aria-hidden="true" onclick="deleteImage(this)"></i>-->
<!--                <img class="img-thumbnail" style="max-width: 150px; max-height: 150px;" src="/resource/images/nopic.jpg" alt="" />-->
<!--            </div>-->
        </div>
EOF;
        $scriptString = <<<EOF
            <script type="text/javascript">
                // 删除当前选择的图片
                function deleteImage(el){
                    $(el).parent().remove();
                    return ;
                }
        </script>
EOF;
        return $elementString . $scriptString;
    }
}


if (!function_exists('view_ueditor')) {
    function view_ueditor($name, $value)
    {
        global $_G;

        $html = <<<EOF
            <script type="text/javascript">
            $(function() {
                var editorConfig = {
                    // 工具栏配置
                    toolbars: [
                        ['source','preview', 'insertimage', 'insertvideo', 'link']
                    ],
                    //默认的编辑区域高度
                    initialFrameHeight: 500,
                    autoHeightEnabled: true, // 开启自动高度调整功能
                    imageUrl: '', // 不设置上传地址
                    imageActionName: '', // 空字符串表示不执行任何操作
                    lang: 'zh-cn', // 设置为中文
                    textarea:'$name',
                    initialContent: '$value', // 设置初始内容
                    elementPathEnabled:false
                }

                ueditorObj['$name'] = UE.getEditor('$name', editorConfig);
                ueditorObj['$name'].ready( function() {
                     var me = this
                     ueditorObj['$name'].addListener('fullscreenchanged', function(type, enabled) {
                       if (type === 'source') {
                           // 设置源码模式下的高度
                           editor.setHeight('800px');
                       } else {
                           // 恢复到正常模式下的高度或者其他逻辑
                       }
                   });
                    ueditorObj['$name'].addListener('keydown', function(cmd,evt) {
                     var range = me.selection.getRange();
                     var child = range.startContainer;
                     if(evt.keyCode === 8  || evt.keyCode === 46) {
                        if(event.target.nodeName === 'VIDEO'){
                            event.target.remove()
                        }
                     }
                  });

                     // 图片插入后修改图片宽度
                     ueditorObj['$name'].addListener('afterinsertimage', function (cmd, insertimg) {
                         var img = insertimg[0]
                         var images = ueditorObj[ueditorIdFlag].body.getElementsByTagName('img');
                         if(images.length > 0) {
                             for(var i=0;i<images.length;i++) {
                                 if(images[i].src === img.src) {
                                     images[i].style.width = '100%'
                                 }
                             }
                         }
                    });

                     // 获取当前绑定的富文本ID
                     var ueditorIdFlag = me.key

                   // 多图上传绑定事件
                   var toolbarDom = this.container.querySelector('.edui-toolbar');
                   var imgUploadBtn = toolbarDom.querySelector('[title="多图上传"]');
                   imgUploadBtn.addEventListener('mousedown', function(e) {

                      $("#confirmSelected").attr('ueditor-flag', ueditorIdFlag)
                      e.stopPropagation();
                      e.preventDefault();
                      e.preventDefault();
                      $("#uploadModal").attr('operate-type', '图片')
                      $('#uploadModal').modal('show')
                   })

                   // 点击视频图标绑定事件
                    var videoButton = toolbarDom.querySelector('[title="视频"]');
                     videoButton.addEventListener('mousedown', function(e) {
                        $("#confirmSelected").attr('ueditor-flag', ueditorIdFlag)
                        e.stopPropagation();
                        e.preventDefault();
                        $("#uploadModal").attr('operate-type', '视频')
                        $('#uploadModal').modal('show')
                   })
                })
            })

            function showCustomVideoUploader(videoUrl){
              var ueditorIdFlag = $("#confirmSelected").attr('ueditor-flag')
                if(!ueditorIdFlag) {
                    layer.msg("富文本绑定参数异常，请联系技术人员")
                    return false;
                }

                // 创建HTML5 <video>标签的内容
                var videoHtml = '<p><video controls width="100%" height="auto" src="' + videoUrl + '"><source src="' + videoUrl + '" type="video/mp4"/></video></p>';

                // 将<video>标签内容插入到编辑器中
                ueditorObj[ueditorIdFlag].execCommand('insertHtml', videoHtml);
            }
            // 假设你已经有了一个函数用于处理用户选中的图片
            function handleSelectedImages(imageUrls) {
                // 获取当前富文档编辑器对象实例绑定的ID，即当前点击时的富文绑定的ID
                var ueditorIdFlag = $("#confirmSelected").attr('ueditor-flag')
                if(!ueditorIdFlag) {
                    layer.msg("富文本绑定参数异常，请联系技术人员")
                    return false;
                }

                // 插入图片并记录下当前插入图片的数量
                if(imageUrls.length > 0) {
                    for (var i = 0; i < imageUrls.length; i++) {
                        ueditorObj[ueditorIdFlag].execCommand('insertimage', {src: imageUrls[i]});
                    }
                } else {
                    console.log('未上传图片，当前无需要执行插入图片操作')
                }
            }
            </script>
            <script id="$name" type="text/plain"></script>
EOF;
        return $html;
    }
}
if (!function_exists('mkdirs')) {
    function mkdirs($path)
    {
        if (!is_dir($path)) {
            mkdirs(dirname($path));
            mkdir($path);
        }
        return is_dir($path);
    }
}